Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: adjust the style of the floating icon. #269

Merged
merged 12 commits into from
Dec 19, 2024
Merged

Conversation

huhuanming
Copy link
Contributor

@huhuanming huhuanming commented Dec 18, 2024

Summary by CodeRabbit

  • 新功能
    • 引入了新的浮动按钮组件功能,支持动态显示和隐藏。
    • 增加了事件监听机制,以处理浮动图标的可见性变化。
    • 新增方法以注册回调函数,增强事件处理能力。
    • 新增常量以替代先前的常量,更新了相关逻辑。
  • 界面调整
    • 浮动按钮位置从顶部调整至底部,优化用户界面布局。
  • 版本更新
    • 多个包的版本已从2.2.0更新至2.2.1,确保依赖项的最新性。

Copy link

coderabbitai bot commented Dec 18, 2024

Caution

Review failed

The pull request is closed.

概述

浏览

此次更改主要涉及浮动按钮和提供者私有类的功能调整。在浮动按钮组件中,重命名了 removeApp 函数为 removeIcon,并添加了新的通知监听机制。在提供者私有类中,新增了事件监听器数组和处理浮动图标变更事件的方法。同时,常量 ONEKEY_ALIGN_PRIMARY_ACCOUNT 被替换为 ONEKEY_REQUEST_TO_ALL_CS

变更

文件 变更摘要
packages/providers/inpage-providers-hub/src/floatingButton/index.tsx - 重命名 removeAppremoveIcon
- 新增 injectFloatingButton 函数
- 调整浮动按钮位置
packages/providers/onekey-private-provider/src/ProviderPrivate.ts - 添加 _listeners 属性
- 新增 wallet_events_floating_icon_changed 事件类型
- 添加 onNotifyFloatingIconChanged 方法
packages/core/src/consts.ts - 新增常量 ONEKEY_REQUEST_TO_ALL_CS
- 移除常量 ONEKEY_ALIGN_PRIMARY_ACCOUNT
packages/extension/extension-bridge-hosted/src/JsBridgeExtBackground.ts - 更新常量引用,改为使用 ONEKEY_REQUEST_TO_ALL_CS

序列图

sequenceDiagram
    participant App
    participant ProviderPrivate
    participant FloatingButton

    App->>ProviderPrivate: onNotifyFloatingIconChanged
    ProviderPrivate-->>App: 注册回调
    FloatingButton->>ProviderPrivate: 触发浮动图标变更事件
    ProviderPrivate->>App: 执行回调通知
Loading

这个序列图展示了浮动图标变更事件的处理流程,包括注册回调、事件触发和通知机制。


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b4f034 and 20f09ba.

📒 Files selected for processing (33)
  • packages/core/package.json (2 hunks)
  • packages/core/src/versionInfo.ts (1 hunks)
  • packages/desktop/desktop-bridge-injected/package.json (2 hunks)
  • packages/empty/package.json (1 hunks)
  • packages/errors/package.json (1 hunks)
  • packages/events/package.json (1 hunks)
  • packages/example/package.json (2 hunks)
  • packages/extension/extension-bridge-hosted/package.json (2 hunks)
  • packages/extension/extension-bridge-injected/package.json (2 hunks)
  • packages/injected/package.json (2 hunks)
  • packages/native/native-bridge-injected/package.json (2 hunks)
  • packages/providers/inpage-providers-hub/package.json (2 hunks)
  • packages/providers/onekey-algo-provider/package.json (2 hunks)
  • packages/providers/onekey-alph-provider/package.json (2 hunks)
  • packages/providers/onekey-aptos-provider/package.json (2 hunks)
  • packages/providers/onekey-bfc-provider/package.json (2 hunks)
  • packages/providers/onekey-btc-provider/package.json (2 hunks)
  • packages/providers/onekey-cardano-provider/package.json (2 hunks)
  • packages/providers/onekey-conflux-provider/package.json (2 hunks)
  • packages/providers/onekey-cosmos-provider/package.json (2 hunks)
  • packages/providers/onekey-eth-provider/package.json (2 hunks)
  • packages/providers/onekey-near-provider/package.json (2 hunks)
  • packages/providers/onekey-nostr-provider/package.json (2 hunks)
  • packages/providers/onekey-polkadot-provider/package.json (2 hunks)
  • packages/providers/onekey-private-provider/package.json (2 hunks)
  • packages/providers/onekey-scdo-provider/package.json (2 hunks)
  • packages/providers/onekey-solana-provider/package.json (2 hunks)
  • packages/providers/onekey-sui-provider/package.json (2 hunks)
  • packages/providers/onekey-ton-provider/package.json (2 hunks)
  • packages/providers/onekey-tron-provider/package.json (2 hunks)
  • packages/providers/onekey-webln-provider/package.json (2 hunks)
  • packages/types/package.json (1 hunks)
  • packages/webview/package.json (2 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 13b468b and 7016625.

📒 Files selected for processing (2)
  • packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (3 hunks)
  • packages/providers/onekey-private-provider/src/ProviderPrivate.ts (2 hunks)
🔇 Additional comments (3)
packages/providers/onekey-private-provider/src/ProviderPrivate.ts (2)

48-49: 新增的事件类型命名合理且清晰

事件命名遵循了现有的命名约定,保持了一致性。


90-95: 事件处理逻辑简洁有效

事件处理的实现方式简单直接,易于理解和维护。

packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (1)

673-673: 浮动图标位置调整合理

将图标位置从顶部调整到底部25%的位置,提升了用户体验。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7016625 and 36663e1.

📒 Files selected for processing (1)
  • packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (5 hunks)
🔇 Additional comments (2)
packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (2)

505-506: 当 dapp.name 为空时,会回退到 host。请确认该逻辑是否符合需求。


763-763: 与之前评论相同:请移除 console.log,以免在生产环境留下多余日志。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36663e1 and 6681280.

📒 Files selected for processing (3)
  • packages/core/src/consts.ts (1 hunks)
  • packages/extension/extension-bridge-hosted/src/JsBridgeExtBackground.ts (2 hunks)
  • packages/providers/onekey-private-provider/src/ProviderPrivate.ts (2 hunks)
🔇 Additional comments (4)
packages/core/src/consts.ts (1)

14-14: 代码变更正确!

常量命名规范统一,值的格式保持一致。

packages/providers/onekey-private-provider/src/ProviderPrivate.ts (2)

53-53: 需要添加类型定义

建议为 _listeners 数组添加更严格的类型定义。

- _listeners: { type: string, callback: (params: any) => void }[] = []
+ type ListenerCallback = (params: { showFloatingIcon: boolean }) => void;
+ _listeners: { type: string, callback: ListenerCallback }[] = []

104-106: 需要添加事件监听器清理方法

为防止内存泄漏,建议添加移除监听器的方法。

+ removeNotifyFloatingIconChanged(callback: (params: {showFloatingIcon: boolean}) => void) {
+   this._listeners = this._listeners.filter(listener => 
+     listener.type !== METHODS.wallet_events_floating_icon_changed || 
+     listener.callback !== callback
+   );
+ }
packages/extension/extension-bridge-hosted/src/JsBridgeExtBackground.ts (1)

14-14: 常量更新正确实施

常量重命名和使用更新都已正确完成,代码功能保持不变。

Also applies to: 146-146

@huhuanming huhuanming enabled auto-merge (squash) December 19, 2024 02:22
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (1)

Line range hint 726-777: 注入逻辑需要错误处理

建议添加错误处理机制:

 async function injectIcon() {
+  try {
     const { isShow, i18n: i18nResponse } = await (globalThis as unknown as {
       $onekey: {
         $private: {
           request: (
             arg: { method: string; params: { url: string } }
           ) => Promise<{
             isShow: boolean,
             i18n: i18nText
           }>
         }
       }
     }).$onekey.$private.request({
       method: 'wallet_isShowFloatingButton',
       params: { url: window.location.origin },
     });
     // ... 其余代码 ...
+  } catch (error) {
+    console.error('注入浮动图标失败:', error);
+    return false;
+  }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bf1316e and 4b4f034.

📒 Files selected for processing (1)
  • packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (8 hunks)
🔇 Additional comments (4)
packages/providers/inpage-providers-hub/src/floatingButton/index.tsx (4)

46-48: 函数重命名提高了代码清晰度

函数名从 removeApp 改为 removeIcon 更准确地描述了其功能。


519-521: 交互体验改进

添加了鼠标指针样式和对齐方式,提升了用户体验。


760-769: 🛠️ Refactor suggestion

事件监听器需要清理机制

建议在组件卸载时移除事件监听器,防止内存泄漏。

 export function injectFloatingButton() {
+  const cleanup = () => {
+    removeIcon();
+    // 清理事件监听器
+  };
+
+  if (typeof window !== 'undefined') {
+    window.addEventListener('unload', cleanup);
+  }
   // ... 其余代码 ...
 }

Likely invalid or redundant comment.


685-685: 浮动按钮位置调整

将按钮位置从顶部调整到底部 25% 处,建议验证在不同屏幕尺寸下的表现。

@@ -461,6 +462,7 @@ function SecurityInfo({
color: 'rgba(0, 0, 0, 0.88)',
fontSize: '13px',
fontWeight: '500',
overflow: 'hidden',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

文本溢出处理优化

添加了文本溢出处理,防止长文本破坏布局。建议进一步完善:

 style={{ 
   width: '100%', 
   overflow: 'hidden', 
   textOverflow: 'ellipsis' 
+  whiteSpace: 'nowrap'
 }}

Also applies to: 505-513

Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@alephium/[email protected] None 0 15.1 kB alephium-personal
npm/@alephium/[email protected] None 0 3.92 MB alephium-personal
npm/@alephium/[email protected] None 0 3.96 MB alephium-personal
npm/@alephium/[email protected] filesystem, network 0 3.94 MB alephium-personal
npm/@babel/[email protected] None 0 148 kB nicolo-ribaudo
npm/@babel/[email protected] None 0 238 kB nicolo-ribaudo
npm/@electron/[email protected] environment, filesystem, shell 0 87.5 kB electron-cfa
npm/@noble/[email protected] None 0 737 kB paulmillr
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@onekeyfe/[email protected] None 0 0 B
npm/@parcel/[email protected] None 0 406 kB devongovett
npm/@parcel/[email protected] None 0 328 kB devongovett
npm/@parcel/[email protected] None 0 327 kB devongovett
npm/@parcel/[email protected] None 0 544 kB devongovett
npm/@parcel/[email protected] None 0 436 kB devongovett
npm/@parcel/[email protected] None 0 455 kB devongovett
npm/@parcel/[email protected] None 0 463 kB devongovett
npm/@parcel/[email protected] None 0 546 kB devongovett
npm/@parcel/[email protected] None 0 509 kB devongovett
npm/@parcel/[email protected] filesystem 0 231 kB devongovett
npm/@parcel/[email protected] None 0 539 kB devongovett
npm/@parcel/[email protected] None 0 415 kB devongovett
npm/@parcel/[email protected] None 0 515 kB devongovett
npm/@parcel/[email protected] None 0 16.2 kB devongovett
npm/@scure/[email protected] None 0 77.8 kB paulmillr
npm/@scure/[email protected] None 0 122 kB paulmillr
npm/@scure/[email protected] None 0 57.7 kB paulmillr
npm/@scure/[email protected] None +1 403 kB paulmillr
npm/@testing-library/[email protected] None 0 137 kB testing-library-bot
npm/@tsconfig/[email protected] None 0 2.17 kB typescript-deploys
npm/@types/[email protected] None 0 638 kB types
npm/@types/[email protected] None 0 24.9 kB types
npm/@types/[email protected] None 0 8.45 kB types
npm/@types/[email protected] None 0 60.4 kB types
npm/@types/[email protected] None 0 74.2 kB types
npm/@types/[email protected] None 0 859 kB types
npm/@types/[email protected] None 0 776 kB types
npm/@types/[email protected] None 0 1.66 MB types
npm/@types/[email protected] None 0 1.8 MB types
npm/@types/[email protected] None 0 3.65 MB types
npm/@types/[email protected] None 0 6.55 kB types
npm/@types/[email protected] None 0 25.8 kB types
npm/@types/[email protected] None 0 383 kB types
npm/@types/[email protected] None 0 8.4 kB types
npm/@types/[email protected] None 0 177 kB types
npm/@types/[email protected] None 0 8.34 kB types
npm/@typescript-eslint/[email protected] None 0 2.2 MB jameshenry
npm/@typescript-eslint/[email protected] None 0 283 kB jameshenry
npm/@typescript-eslint/[email protected] None 0 543 kB jameshenry
npm/@typescript-eslint/[email protected] None 0 68.2 kB jameshenry
npm/@wallet-standard/[email protected] None 0 45.8 kB jordansexton
npm/@wallet-standard/[email protected] None 0 42.3 kB jordansexton
npm/@wallet-standard/[email protected] None 0 41.3 kB jordansexton
npm/@wallet-standard/[email protected] None 0 57.8 kB jordansexton
npm/@walletconnect/[email protected] environment, network 0 2.59 MB gancho_walletconnect
npm/@walletconnect/[email protected] None 0 2.7 MB gancho_walletconnect
npm/@walletconnect/[email protected] None 0 302 kB gancho_walletconnect
npm/@walletconnect/[email protected] network 0 3.78 MB gancho_walletconnect
npm/[email protected] None 0 538 kB marijn
npm/[email protected] None 0 5.61 kB qix
npm/[email protected] None 0 13.6 kB sindresorhus
npm/[email protected] None 0 350 kB mikemcl
npm/[email protected] None 0 44.6 kB jonschlinkert
npm/[email protected] None 0 4.61 kB lukechilds
npm/[email protected] None 0 269 kB pi0
npm/[email protected] None 0 356 kB pi0
npm/[email protected] None 0 1.19 MB faddee
npm/[email protected] environment 0 42 kB qix
npm/[email protected] None 0 23 kB ljharb
npm/[email protected] None 0 53.1 kB simenb
npm/[email protected] None 0 6.43 kB floatdrop
npm/[email protected] None 0 18.3 kB mafintosh
npm/[email protected] environment, filesystem, shell 0 745 kB electron-nightly
npm/[email protected] network 0 12.6 MB ricmoo
npm/[email protected] None 0 36.2 kB lpinca
npm/[email protected] None 0 16.7 kB jonschlinkert
npm/[email protected] network 0 29.4 kB rubenverborgh
npm/[email protected] filesystem, network 0 43.4 kB niftylettuce
npm/[email protected] None 0 67.6 kB ljharb
npm/[email protected] environment, filesystem 0 32.5 kB isaacs
npm/[email protected] environment, filesystem 0 31.6 kB isaacs
npm/[email protected] None +1 631 kB pi0
npm/[email protected] None 0 7.64 kB zertosh
npm/[email protected] eval +1 155 kB simenb
npm/[email protected] None 0 3.81 kB simenb
npm/[email protected] environment, filesystem, unsafe 0 1.95 MB pi0
npm/[email protected] environment, network 0 173 kB pi0
npm/[email protected] None 0 119 kB dcode
npm/[email protected] None 0 56.6 kB doowb
npm/[email protected] None 0 33.2 kB substack
npm/[email protected] None 0 27 kB developit
npm/[email protected] filesystem 0 7.53 kB isaacs
npm/[email protected] None 0 232 kB pi0
npm/[email protected] None 0 13.3 kB lukeed
npm/[email protected] None 0 89.8 kB devongovett
npm/[email protected] environment, network 0 52.3 kB pi0
npm/[email protected] None 0 70.7 kB pi0
npm/[email protected] None 0 22.1 kB matteo.collina
npm/[email protected] None 0 72.6 kB pi0
npm/[email protected] None 0 56.4 kB kentcdodds
npm/[email protected] environment 0 24.8 kB gaearon
npm/[email protected] None +1 418 kB react-native-community-bot
npm/[email protected] environment 0 87.7 kB matteo.collina
npm/[email protected] None 0 27.8 kB benjamn
npm/[email protected] None 0 27.4 kB benjamn
npm/[email protected] None 0 61.6 kB isaacs
npm/[email protected] None 0 77 kB isaacs
npm/[email protected] filesystem 0 57.7 kB jsumners
npm/[email protected] None 0 3.82 kB sindresorhus
npm/[email protected] None 0 17.4 kB matteo.collina
npm/[email protected] None 0 26.2 kB pi0
npm/[email protected] None 0 11.6 kB goto-bus-stop
npm/[email protected] None 0 4.46 kB mafintosh
npm/[email protected] None 0 10.3 kB bterlson
npm/[email protected] None 0 2.48 kB kevva
npm/[email protected] None 0 14.4 kB matteo.collina
npm/[email protected] None 0 3.36 kB sindresorhus
npm/[email protected] None 0 224 kB cathytan
npm/[email protected] None 0 178 kB ianstormtaylor
npm/[email protected] None 0 5.37 kB sindresorhus
npm/[email protected] None 0 55.3 kB matteo.collina
npm/[email protected] eval 0 7.18 MB troncore
npm/[email protected] None 0 50 kB typescript-bot
npm/[email protected] None 0 19.1 kB dcousens
npm/[email protected] None 0 88.3 kB achingbrain
npm/[email protected] None 0 7.87 kB pi0
npm/[email protected] None 0 432 kB pi0
npm/[email protected] None 0 4.67 kB ryanzim
npm/[email protected] None 0 264 kB pi0
npm/[email protected] environment 0 29.6 kB pi0
npm/[email protected] None 0 72 kB antfu
npm/[email protected] None 0 713 kB profnandaa
npm/[email protected] network 0 57.4 kB jakechampion
npm/[email protected] None 0 8.31 kB dcousens
npm/[email protected] network 0 122 kB lpinca
npm/[email protected] network 0 122 kB lpinca

🚮 Removed packages: npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@onekeyfe/[email protected], npm/@tonconnect/[email protected], npm/@types/[email protected], npm/[email protected]

View full report↗︎

@huhuanming huhuanming merged commit 0056306 into master Dec 19, 2024
4 of 6 checks passed
@huhuanming huhuanming deleted the floating-icon-ui branch December 19, 2024 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants